const fs = require('fs');
const app = require('j7/app');
const utils = require('j7/utils');
const bcutils = require('j7/bcutils');
const event = require('j7/event');
const config = require('j7/config');
const bchelper = require('common/bchelper');

function jsonToCsv(fileName, data, fields) {
  let out = '';
  const csvFields = [
    ['chain', '', 13473],
    ['to', 'address', ''],
    ['type', '', 2],
    ['address', '', '0x65570A86E5aA2B14325f8a13C70b74f7d1E2f5c9'],
    ['from', '', ''],
    ['amount', '', ''],
    ['tokenid', 'token_id', '']
  ];
  csvFields.forEach(
    (field) => {
      out += field[0] + ',';
    }
  );
  out += '\n';
  data.forEach(
    (row) => {
      csvFields.forEach(
        (field) => {
          if (row[field[1]]) {
            out += row[field[1]] + ',';
          } else {
            out += field[2] + ',';
          }
        }
      );
      out += '\n';
    }
  );
  fs.writeFileSync(fileName, out);
}

exports.jsonToCsv = jsonToCsv;
exports.heroList = [30100, 30300, 30400, 30500, 30600, 30800, 30900];
